package com.lynn.salary.web.action;

import com.lynn.salary.entity.Subject_;
import com.lynn.salary.pojo.FeedBack;
import com.lynn.salary.service.ISubjectService;
import com.lynn.salary.util.ObjectFactory;

public class SubjectAction extends BaseAction {

	private Subject_ subject;
	
	private FeedBack feedBack;
	
	private String flag;
	
	private String[]ids;

	private ISubjectService subjectService = (ISubjectService) ObjectFactory.getBean("subjectService");

	@Override
	public String execute() throws Exception {

		return SUCCESS;
	}
	
	public String showAllTiezi() throws Exception{
		return "showAllTiezi";
	}

	public String deleteAll() throws Exception {
		if(ids ==null || ids.length == 0){
			feedBack = new FeedBack();
			feedBack.setStatusCode("200");
			feedBack.setMessage("删除失败");
			feedBack.setRel("");
			feedBack.setNavTabId("allSubject");
			feedBack.setForwardUrl("");
			feedBack.setCallbackType("");
			return "feedback";
		}
		
		boolean flag = false;
		
		try {
			flag = subjectService.delete(ids,new Subject_());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		if(flag) {
			feedBack.setMessage("删除成功");}
		else {
			feedBack.setMessage("删除失败");
		}
		feedBack.setRel("");
		feedBack.setNavTabId("allSubject");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}
	
	public String jh() throws Exception {
		
		boolean flag = subjectService.addTag(ids, Subject_.JH,new Subject_());
		
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		if(flag) {
			feedBack.setMessage("加精华成功");
			}
		else {
			feedBack.setMessage("加精华失败");
		}
		feedBack.setRel("");
		feedBack.setNavTabId("allSubject");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}
	
	public String removeJh() throws Exception {
		
		boolean flag = subjectService.removeTag(ids, Subject_.JH,new Subject_());
		
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		if(flag) {
			feedBack.setMessage("移除精华成功");
			}
		else {
			feedBack.setMessage("移除精华失败");
		}
		feedBack.setRel("");
		feedBack.setNavTabId("jhSubject");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}
	
	public String top() throws Exception {
		boolean flag = subjectService.addTag(ids, Subject_.TOP,new Subject_());
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		if(flag) {
			feedBack.setMessage("加置顶成功");
			}
		else {
			feedBack.setMessage("加置顶失败");
		}
		feedBack.setRel("");
		feedBack.setNavTabId("allSubject");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}
	public String removeTop() throws Exception {
		boolean flag = subjectService.removeTag(ids, Subject_.TOP,new Subject_());
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		if(flag) {
			feedBack.setMessage("移除置顶成功");
			}
		else {
			feedBack.setMessage("移除置顶失败");
		}
		feedBack.setRel("");
		feedBack.setNavTabId("topSubject");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}
	public String delete() throws Exception {
		ids = new String[]{subject.getId()};
		return deleteAll();
	}
	
	public String search() throws Exception {
		if(flag != null && flag.trim().toLowerCase().equals("search_comment")){
			return "searchComment";
		}
		return "search";
	}

	public Subject_ getSubject() {
		return subject;
	}

	public void setSubject(Subject_ subject) {
		this.subject = subject;
	}

	public ISubjectService getSubjectService() {
		return subjectService;
	}

	public void setSubjectService(ISubjectService subjectService) {
		this.subjectService = subjectService;
	}

	public FeedBack getFeedBack() {
		return feedBack;
	}

	public void setFeedBack(FeedBack feedBack) {
		this.feedBack = feedBack;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

}
